package gwt.coonay.server;
import gwt.coonay.client.NoteDTO;

import java.lang.reflect.InvocationTargetException;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;


@Entity
@NamedQuery(
	name = "Note.listAll", query = "SELECT n FROM gwt.coonay.server.Note n"
)
public class Note extends NoteDTO{
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
	public String mail2;
	
	
	
	public static Note newInstance(NoteDTO nd) {
		try {
			Note n = new Note();
			BeanUtils.copyProperties(n,nd);
			
			Logger.getLogger(Note.class).info("mail="+n.getGmail());
			return n;
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return null;
		
	}
	
	public static NoteDTO newRootInstance(Note n) {
		try {
			NoteDTO nd = new NoteDTO();
			BeanUtils.copyProperties(nd,n);
			return nd;
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return null;
		
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	public Long getId() {
		return id;
	}
	
	
	
	

}
